package org.example.view.Frame;

import org.example.view.componet.ATMButton;
import org.example.view.componet.BackgroundScene;
import org.example.view.componet.ButtonTypeEnum;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * 登录页面
 */
public class LoginAtm extends JPanel {
    /**
     * 背景
     */
    private BackgroundScene backgroundScene;

    /**
     * 退出按钮
     */
    private ATMButton offButton;
    /**
     * 清除按钮
     */
    private ATMButton clearButton;

    /**
     * 确认按钮
     */
    private ATMButton sureButton;

    /**
     * 操作框
     */
    private JLabel imgLabel;

    /**
     * 账号输入框
     */
    private JTextField userNameInput;

    /**
     * 密码输入框
     */
    private JPasswordField passwordInput;

    /**
     * 账号提示
     */
    private JLabel userName;

    /**
     * 密码提示
     */
    private JLabel password;

    public LoginAtm(JPanel panel) {
        this.addContent(panel);
    }

    private void addContent(JPanel panel) {
        this.setLayout(null);

        /**
         * 退出按钮（跳转主页）
         */
        this.offButton = new ATMButton(ButtonTypeEnum.退出, 450, 650);
        this.offButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "main");
            }
        });
        this.add(this.offButton);

        /**
         * 清除按钮（清除输入的用户名和密码）
         */
        this.clearButton = new ATMButton(ButtonTypeEnum.清除, 20, 475);
        this.clearButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                userNameInput.setText(null);
                passwordInput.setText(null);
            }
        });
        this.add(this.clearButton);

        /**
         * 确认按钮（提交用户名和密码）
         */
        this.sureButton = new ATMButton(ButtonTypeEnum.确定, 880, 475);
        this.sureButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
//                if (){
                    cardLayout.show(panel, "choose");
//                }
            }
        });
        this.add(this.sureButton);

        /**
         * 账号提示
         */
        this.userName = new JLabel();
        this.userName.setText("请输入用户名：");
        this.userName.setFont(new Font("宋体", Font.ITALIC, 21));
        this.userName.setForeground(Color.blue);
        this.userName.setBounds(260, 290, 150, 25);
        this.add(this.userName);

        /**
         * 账号输入
         */
        this.userNameInput = new JTextField();
        this.userNameInput.setBounds(425, 280, 200, 35);
        this.add(this.userNameInput);

        /**
         * 密码提示
         */
        this.password = new JLabel();
        this.password.setText("请输入密码：");
        this.password.setFont(new Font("宋体", Font.ITALIC, 21));
        this.password.setForeground(Color.blue);
        this.password.setBounds(260, 350, 150, 25);
        this.add(this.password);

        /**
         * 密码输入
         */
        this.passwordInput = new JPasswordField();
        this.passwordInput.setBounds(425, 345, 200, 35);
        this.add(this.passwordInput);

        /**
         * 操作框
         */
        this.imgLabel = new JLabel(new ImageIcon("/Users/cengyunke/Desktop/atm1/ATMGUI/src/main/java/org/example/img/pane.jpg"));
        this.imgLabel.setBounds(210, 250, 620, 200);
        this.add(this.imgLabel);

        /**
         * 背景
         */
        this.backgroundScene = new BackgroundScene();
        this.add(this.backgroundScene);
    }
}
